package com.gagakuai.bpm.common.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/*
 * @program: blog
 * @description:
 * @author: houhong 用于复用request的i/o流
 * @create: 2022-01-23 22:19
 */
@WebFilter("/*")
public class WrapperOrderFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    /*
     *
     * 复用流
     *
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;

        ServletRequest requestWrapper = new ContentCachingRequestWrapperNew(httpServletRequest);

        requestWrapper.setCharacterEncoding("utf-8");
        servletResponse.setCharacterEncoding("utf-8");

        filterChain.doFilter(requestWrapper, servletResponse);
    }

    @Override
    public void destroy() {

    }
}